package edu.sctu.treebuilder.day02;

/**
 * Created by apple on 05/02/2018.
 */
public abstract class Token {
    TokenType type;

    static abstract class Tag extends Token {
        String tagName;

        public Tag() {
            super();
        }

        public void appendTagName(String append) {

            tagName = tagName == null ? append : tagName.concat(append);
        }

        public void appendTagName(char ch) {

            appendTagName(String.valueOf(ch));
        }

        public Tag reset() {
            tagName = null;
            return this;
        }
    }

    static final class StartTag extends Tag {

        public StartTag() {
            super();
            type = TokenType.StartTag;
        }
    }

    static final class EndTag extends Tag {
        public EndTag() {
            super();
            type = TokenType.EndTag;
        }
    }

    static final class Character extends Token {

        String data;

        public Character() {
            super();
            type = TokenType.Character;
        }

        public Character(String data) {
            super();
            this.type = TokenType.Character;
            this.data = data;
        }
    }

    static final class EOF extends Token {

        public EOF() {
            super();
            type = TokenType.EOF;
        }
    }

    enum TokenType {
        StartTag,
        EndTag,
        Character,
        EOF
    }
}
